sink(here("..", "results", "log_examples.txt"))


########################################################
######          Replication Code for              ######
######            Bias due to network      	  ######
######  misspecification under spatial dependence ######
######       					  ######
########################################################
######                                            ######
######                11/05/2019                  ######
######   this file runs code to estimate          ######
######  the applied examples mentioned in paper   ######
###### (note that the original data analysis      ######
######  estimated robust SEs -- we do not care    ######
######    about SEs here)                         ######
########################################################



tic("Examples")

data  <- read_dta(here("..", "data", "KP2012_Benchmarking_Agg_Data.dta"))

m1  <- lm(votelead ~ gr_an + coalsize + enep + pop + elecyr, data = data[is.na(data$gr_glob_tr_an) == F, ])
#### biased beta_1
cat(paste("biased beta_1:", round(summary(m1)$coefficients[2, 1], 3)))


m2  <- lm(votelead ~ gr_glob_tr_an + gr_an + coalsize + enep + pop + elecyr, data =  data[is.na(data$gr_glob_tr_an) == F, ])
#### beta_1 and theta
cat(paste("beta_1 and theta:", round(summary(m2)$coefficients[c(2, 3),1 ], 3)))




m3  <- lm(gr_glob_tr_an ~ gr_an + coalsize + enep + pop + elecyr, data = data[is.na(data$gr_glob_tr_an) == F & is.na(data$votelead) == F, ])
##### Cov(x,Wx)/Var(x)
cat(paste("Cov(x,Wx)/Var(x):", round(summary(m3)$coefficients[2,1 ], 3)))

toc()

sink()
